package d1208.Ljs2.Ljs18;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.lang.reflect.Constructor;
import java.util.List;

public class Test {
    //18.反射
    //1.现有Person类，包含属性String id，String name ，int age
    //2.data1.txt中存放了Person类的全限定名（包名+类名）,data2.txt中存放了 Person类的属性信息内容如下
    //id=p001
    //name=小虎
    //age=20
    //3.定义测试类，在测试类中通过解析data1.txt，使用反射来获取Person实例。通过解析data2.txt来给Person赋值。
    public static void main(String[] args) throws Exception {
        List<String> list = FileUtils.readLines(new File("Ljs2/Ljs18/data1.txt"));
        List<String> list1 = FileUtils.readLines(new File("Ljs2/Ljs18/data2.txt"));
        String str = "";
        for (int i = 0; i < list.size(); i++) {
            str += list.get(i);
        }
        Class<?> aClass = Class.forName(str);
        Constructor<?> constructor = aClass.getConstructor(String.class,String.class,int.class);
        for (int i = 0; i < list1.size(); i++) {
            String[] arr = list1.get(i).split("=");
            Object o = constructor.newInstance(arr[0], arr[1], Integer.parseInt(arr[2]));
        }


    }
}
